using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using CE.Database;

/// <summary>
/// Summary description for CompanyDB
/// </summary>
/// 
namespace CE.Provider
{
    public class ProviderTypeDB
    {
        public ProviderTypeDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public DataTable GetAssignmentList(Int64 ProviderCompanyId, Int64 CEID)
        {
            MyDatabase _db = new MyDatabase();
            string strSQL = "SELECT ProviderTypeId FROM tblProviderTypeLink WHERE ProviderCompanyID = @ProviderCompanyID AND CEID = @CEID";
            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            _sPara.Add("@CEID", CEID);
            #endregion

            DataTable _result = _db.GetDataTable(strSQL, _sPara);
            return _result;
        }

        public bool DeleteAllAssignment(Int64 ProviderCompanyId, Int64 CEID)
        {
            MyDatabase _db = new MyDatabase();
            string strSQL = "DELETE FROM tblProviderTypeLink WHERE ProviderCompanyID = @ProviderCompanyID AND CEID = @CEID";
            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            _sPara.Add("@CEID", CEID);
            #endregion

            int _result = _db.ExecuteNonSqlStatement(strSQL, _sPara);
            return _result > 0;
        }

        public bool AssignProviderType(ProviderType ProType)
        {
            MyDatabase _db = new MyDatabase();
            string strSQL = "INSERT INTO tblProviderTypeLink(CEID, ProviderCompanyID, ProviderTypeID, IsAllow, Status, RefCEUserId) " +
                            " Values(@CEID, @ProviderCompanyID, @ProviderTypeID, @IsAllow, @Status, @RefCEUserId) ";
            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CEID", ProType.CEID);
            _sPara.Add("@ProviderCompanyId", ProType.ProviderCompanyId);
            _sPara.Add("@ProviderTypeID", ProType.ProviderTypeId);
            _sPara.Add("@IsAllow", ProType.IsAllow);
            _sPara.Add("@Status", ProType.Status);
            _sPara.Add("@RefCEUserId", ProType.RefCEUserID);
            #endregion

            int _result = _db.ExecuteNonSqlStatement(strSQL, _sPara);
            return _result > 0;
        }

    }
}